package zju.lzy.runner;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import zju.lzy.service.IOTProperties;
import zju.lzy.service.device.DeviceService;
import zju.lzy.service.message.MessageReceiver;
import zju.lzy.service.stat.StatService;
import zju.lzy.util.BSUtil;


@Component
public class MyRunner implements ApplicationRunner {

    private static final Logger logger = LoggerFactory.getLogger(MyRunner.class);

    @Value("${server.port}")
    int port;

    @Value("${mosquitto.path}\\mosquitto.exe")
    String mosquittoPath;

    @Autowired
    IOTProperties properties;

    @Autowired
    private MessageReceiver messageReceiver;

    @Autowired
    private DeviceService deviceService;

    @Autowired
    private StatService statService;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        System.out.println("here at "+port);
        System.out.println(mosquittoPath);
        System.out.println(properties);
        BSUtil.iotProperties = properties;
        messageReceiver.start();
        deviceService.restartDevices();
        statService.start();

    }
}
